/***************************************************************************
 *   oboe.math.Number2D							*
 *   Copyright (C) 2011 by Felipe Manga					*
 *   lufeboma@gmail.com							*
 *									 *
 *   Permission is hereby granted, free of charge, to any person obtaining *
 *   a copy of this software and associated documentation files (the	   *
 *   "Software"), to deal in the Software without restriction, including   *
 *   without limitation the rights to use, copy, modify, merge, publish,   *
 *   distribute, sublicense, and/or sell copies of the Software, and to	*
 *   permit persons to whom the Software is furnished to do so, subject to *
 *   the following conditions:						 *
 *									 *
 *   The above copyright notice and this permission notice shall be	*
 *   included in all copies or substantial portions of the Software.	   *
 *									 *
 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,	   *
 *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF	*
 *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
 *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR	 *
 *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
 *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
 *   OTHER DEALINGS IN THE SOFTWARE.					   *
 ***************************************************************************/

package oboe.math;

class Number2D
{
public var x : Float;
public var y : Float;
public function new( x:Float=0, y:Float=0 )
{
	this.x = x;
	this.y = y;
}
public function set( x : Float, y : Float ) : Float2D
{
	this.x = x;
	this.y = y;
	return this;
}
public function clone() : Float2D
{
	return new Number2D( x, y );
}
public function isEqual( o : Float2D ) : Bool
{
	return this.x == o.x && this.y == o.y;
}
public function normalize() : Float2D {
	var l : Float = Math.sqrt(x*x+y*y);
	x /= l;
	y /= l;
	return this;
}
public function length() : Float {
	return Math.sqrt(x*x+y*y);
}
public function mul( f : Float ) : Float2D {
	x *= f;
	y *= f;
	return this;
} 
public function sub( s : Float ) : Float2D {
	x -= s;
	y -= s;
	return this;
}
public function sub3( a : Float, b : Float ) : Float2D {
	x -= a;
	y -= b;
	return this;
}
public function sub2( s : Float2D ) : Float2D {
	x -= s.x;
	y -= s.y;
	return this;
}
public function add( n : Float ) : Float2D {
	x += n;
	y += n;
	return this;
}
public function add2( n : Float2D ) : Float2D {
	x += n.x;
	y += n.y;
	return this;
}
public function mul2( n : Float2D ) : Float2D {
	x *= n.x;
	y *= n.y;
	return this;
}
public function addRandom( min : Float, max : Float ) : Float2D {
	x += min + Math.random()*(max-min);
	y += min + Math.random()*(max-min);
	return this;
}
public function mulRandom( min : Float, max : Float ) : Float2D {
	x *= min + Math.random()*(max-min);
	y *= min + Math.random()*(max-min);
	return this;
}
public function copyTo( n : Float2D ) : Float2D {
	n.x = x;
	n.y = y;
	return n;
}
public function copyFrom( n : Object ) : Float2D {
	x = n.x;
	y = n.y;
	return this;
}
public function round() : Float2D {
	x = int(x+0.5);
	y = int(y+0.5);
	return this;
}
public function floor() : Float2D {
	x = int(x);
	y = int(y);
	return this;
}
public function flip() : Float2D {
	var t : Float = y;
	y = x;
	x = t;
	return this;
}
public function toString() : String {
	return "{ x: " + x + ", y: " + y + " }"; 
}
}